package apps.softtech.fastmarket;
import java.util.List;
import java.util.Vector;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
import apps.softtech.fastmarket.adapter.AdapterPager;
import apps.softtech.fastmarket.listenner.ListenerTabHost;
import apps.softtech.fastmarket.listenner.ListenerViewPager;

public class ActivityProductList extends FragmentActivity{
 
    private TabHost mTabHost;
    private ViewPager mViewPager;
    private AdapterPager mPagerAdapter;
    private ListenerTabHost listenerTabHost;
    private ListenerViewPager listenerViewPager;
    /**
     * overide Oncreate
     */
    @SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_productlist);
        //action bar
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setTitle("List Product");
        //init TabHost
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();
        //init view page
        intialiseViewPager();
        //
        //listenner tab host //
        //
        listenerTabHost = new ListenerTabHost(mTabHost, mViewPager, ActivityProductList.this);
        listenerTabHost.createTab();
        listenerTabHost.setBackgroundTabSelect();
        mTabHost.setOnTabChangedListener(listenerTabHost);
        //
        //listener view page
        //
        listenerViewPager = new ListenerViewPager(mTabHost, mViewPager, ActivityProductList.this);
        mViewPager.setOnPageChangeListener(listenerViewPager);
//        /**
//         * test start service
//         */
        Intent intent = new Intent(this,ServiceShowChatHead.class);
        this.startService(intent);
        
    }
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
	}
    /**
     * Initialise ViewPager
     */
    private void intialiseViewPager() {
        List<Fragment> fragments = new Vector<Fragment>();
        fragments.add(Fragment.instantiate(this, FragmentTabHome.class.getName()));
        fragments.add(Fragment.instantiate(this, FragmentTabCategory.class.getName()));
        fragments.add(Fragment.instantiate(this, FragmentTabNew.class.getName()));
        fragments.add(Fragment.instantiate(this, FragmentTabHistory.class.getName()));
        fragments.add(Fragment.instantiate(this, FragmentTabNotification.class.getName()));
        this.mPagerAdapter  = new AdapterPager(super.getSupportFragmentManager(), fragments);
        this.mViewPager = (ViewPager)super.findViewById(R.id.viewpager);
        this.mViewPager.setAdapter(this.mPagerAdapter);
    }

}